<template>
  <div class="app-container">
    <div class="div-sch">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="策略名" prop="strategyName">
          <el-input
            v-model="queryParams.strategyName"
            placeholder="请输入策略名"
            clearable
            style="width: 240px;"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>

        <el-form-item label="标签名" prop="tagName">
          <el-input
            v-model="queryParams.tagName"
            placeholder="请输入标签名"
            clearable
            style="width: 240px;"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>

        <el-form-item label="员工名" prop="staffName">
          <el-input
            v-model="queryParams.staffName"
            placeholder="请输入员工名"
            clearable
            style="width: 240px;"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="div-t">
      <el-row :gutter="10" class="mb8">
        <!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> -->
      </el-row>

      <el-table ref="tables"  border  :data="list"  @selection-change="handleSelectionChange" :default-sort="defaultSort" @sort-change="handleSortChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="策略名"  align="center" prop="strategyName" />
        <el-table-column label="标签名"  align="center" prop="tagName" />
        <el-table-column label="工号"  align="center" prop="staffId" />
        <el-table-column label="姓名"  align="center" prop="staffName" />
        <el-table-column label="手机号"  align="center" prop="phone" />
        <el-table-column label="证件号"  align="center" prop="idNum" />
        <el-table-column label="卡号"  align="center" prop="cardNum" />
        <el-table-column label="部门"  align="center" prop="deptId" />
      </el-table>
      
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { strategyApi } from "@/api/business/strategy";

export default {
  name: "Operlog",
  data() {
    return {
      tableHeight:0,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 选中标签id数组
      tagIds: [],
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 默认排序
      defaultSort: {prop: 'tagName', order: 'descending'},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tagName: undefined,
        staffName: undefined
      },
    };
  },
  created() {
    this.getTableHeight();
  },
  methods: {
    getTableHeight(){
      this.tableHeight = window.innerHeight - 300;
    },
    /** 查询 */
    getList() {
      this.loading = true;
      if(this.queryParams.strategyName == undefined && this.queryParams.deviceName == undefined ){
        this.$message.warning('请输入查询条件!');
        this.loading = false;
        return;
      }
      strategyApi.getAccessStaff(this.queryParams).then( res => {
          this.list = res.data.records;
          this.total = res.data.total;
          this.loading = false;
        }
      ).catch(err=>{
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.$refs.tables.sort(this.defaultSort.prop, this.defaultSort.order)
      this.handleQuery();
    },
    /** 多选框选中数据 */
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.tagIds = selection.map(item => item.tagId)
      this.multiple = !selection.length
    },
    /** 排序触发事件 */
    handleSortChange(column, prop, order) {
      this.queryParams.orderByColumn = column.prop;
      this.queryParams.isAsc = column.order;
      this.getList();
    },
  }
};
</script>
<style  >
.div-t {
  background: white;
  padding: 10px 10px 20px 10px;
  border-radius: 5px;
  /* border: 1px solid rgb(211, 208, 208); */
}
.div-sch {
  background: white;
  padding: 10px 10px 0px 10px;
  border-radius: 5px;
  margin-bottom: 10px;
}
</style>